﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SimpleFileManager.Manager;

namespace SimpleFileManager
{
    public class FormMainPresenter : Presenter<FormMain>
    {
        private FileManager _fileManager;

        public FormMainPresenter(FileManager fileManager)
        {
            _fileManager = fileManager;
            fileManager.OnChangeFolder += new FolderActionEventHandler(fileManager_OnChangeDirectory);
            fileManager.OnSortPanelItems += new FolderActionEventHandler(fileManager_OnSortPanelItems);
            fileManager.OnChangePanels+=new EventHandler(OnChangePanels);
        }

        void fileManager_OnChangeDirectory(object sender, FolderActionEventArgs e)
        {
            View.ShowFolderContent(e.DirectoryIterator,e.IsPanelActive);
        }

        void fileManager_OnSortPanelItems(object sender, FolderActionEventArgs e)
        {
            View.ShowFolderContent(e.DirectoryIterator,e.IsPanelActive);
        }

        void OnChangePanels(object sender, EventArgs args)
        {
            View.ChangeViews();
        }

        public void ChangePanels()
        {
            _fileManager.ChangePanels();
        }

        public void SortPanelItems(Comparison<IFilePanelItem> comparer)
        {
            _fileManager.SortPanelItems(comparer);
        }

        public void GoToParentDirectory()
        {
            _fileManager.GoToParentFolder();
        }

        public void GoToRootDirectory()
        {
            _fileManager.GoToRootFolder();
        }

        public void Refresh()
        {
            _fileManager.Refresh();
        }

        public void GoBack()
        {
            _fileManager.GoBackward();
        }

        public void GoForward()
        {
            _fileManager.GoForward();
        }

        public void Create(IFilePanelItem item)
        {
            _fileManager.Create(item);
        }

        public void ApplyFileFilter(string searchPattern)
        {
            _fileManager.ApplyFileFilter(searchPattern);
        }

        public void Rename(IFilePanelItem item, string newName)
        {
            _fileManager.Rename(item, newName);
        }

        public void Copy(IFilePanelItem item)
        {
            _fileManager.Copy(item);
        }

        public void Delete(IFilePanelItem item)
        {
            _fileManager.Delete(item);
        }

        public void Move(IFilePanelItem item)
        {
            _fileManager.Move(item);
        }

        public void SaveState(string path)
        {
            _fileManager.SaveState(path);
        }

        public void LoadState(string path)
        {
            _fileManager.LoadState(path);
        }

        public IFolderIterator GetDrives()
        {
            return _fileManager.GetDrives();
        }

        public void MakeAction(IFilePanelItem item)
        {
            _fileManager.MakeAction(item);
        }

    }
}
